#ifndef CMSG_H_
#define CMSG_H_
/*********************************************************/
#include "Poco/Runnable.h"
#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeIterator.h>
#include <Poco/Net/SocketAddress.h>

#include <string>
/*********************************************************/
class cMsg : public Poco::Runnable
{
private:
	// Methods
	void run() { execute(); }
	virtual void deserialize(Poco::XML::NodeIterator&) = 0;	// Deserializes a job

protected:
	// Members
	mutable unsigned long 		id;			// The job id ( used for unique identification together with the sender ip/port)
	Poco::Net::SocketAddress	addr;			// The address from which the job was issued

	// Methods
	void ack() const;					// Acknowledge this message

public:
	// Methods
	void setSenderAddr(const Poco::Net::SocketAddress&);	// Set the sender address in the job
	Poco::Net::SocketAddress getSenderAddr() const;		// Returns the address from which the job came from
	void setID(const unsigned long);			// Sets the id of the message
	unsigned long getID() const;				// Returns the id of the message
	cMsg* getAck() const;					// Returns the corresponding acknowledgement packet for this message

	static cMsg* deserialize(const std::string&);		// Create a job from an xml string
	virtual std::string serialize() const = 0;		// Serialize the job to an xml string
	virtual void execute() = 0; 				// Execute the job

	// Construction & Destruction
	cMsg() {};
	virtual ~cMsg() {};
};
/*********************************************************/
#endif //CMSG_H_
